<template>
  <div>
    <div class="top">
      <van-icon @click="goback" class="zuo" name="arrow-left" />
      收货地址
    </div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      :disabled-list="disabledList"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { resslist, removeress } from "@/api/address";
import { Toast, Dialog } from "vant";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      disabledList: [
        {
          id: "3",
          name: "王五",
          tel: "1320000000",
          address: "浙江省杭州市滨江区江南大道 15 号",
        },
      ],
    };
  },
  methods: {
    goback() {
      this.$router.back();
    },
    onAdd() {
      this.$router.push("/AddRess");
      Toast("新增地址");
    },
    onEdit(item, index) {
      // console.log(item, index);
      // Toast("删除地址");
      Dialog.confirm({
        title: "标题",
        message: "弹窗内容",
      })
        .then(() => {
          Toast("确认");
          removeress({ addressid: item.addressid }).then((res) => {
            console.log(res);
            window.location.reload();
          });
        })
        .catch(() => {
          Toast("取消");
        });
    },
  },
  created() {
    resslist({ userid: localStorage.getItem("userid") }).then((res) => {
      console.log(res);
      let newlist = [{}];
      this.list = res.data.data;
    });
  },
};
</script>

<style scoped>
.top {
  width: 100%;
  height: 3.125rem;
  font-size: 1.25rem;
  text-align: center;
  line-height: 3.125rem;
  border-bottom: 0.0625rem solid black;
  background-color: red;
  position: relative;
}
.zuo {
  position: absolute;
  left: 0.625rem;
  font-size: 1.25rem;
  top: 0.9375rem;
}
</style>